import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../public.dart';

class RefreshConfig extends StatelessWidget {
  final Widget child;
  const RefreshConfig({Key key, this.child})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
        footerTriggerDistance: 15,
        dragSpeedRatio: 0.91,
        headerBuilder: () => CustomHeader(
              builder: (BuildContext context, RefreshStatus mode) {
                LogUtil.v(mode, tag: 'headerBuilder===>');
                String text = '';
                if (mode == RefreshStatus.idle) {
                  text = '下拉刷新哦';
                } else if (mode == RefreshStatus.canRefresh) {
                  text = '好了快放开我';
                } else if (mode == RefreshStatus.refreshing) {
                  text = '刷新中';
                } else if (mode == RefreshStatus.completed) {
                  text = '刷新完成';
                } else if (mode == RefreshStatus.failed) {
                  text = '刷新失败';
                }

                return Container(
                    child: Column(children: [
                  ImagesGif(
                      path: 'assets/images/download',
                      highIndex: 20,
                      width: 36,
                      height: 36,
                      duration: Duration(milliseconds: 1400)),
                  Text(
                    text,
                    style: TextStyle(color: ColorUtil.rgba(255, 255, 255, 0.1)),
                  )
                ]));
              },
            ),
        footerBuilder: () => CustomFooter(
              builder: (BuildContext context, LoadStatus mode) {
                String text = '';
                LogUtil.v(mode, tag: 'footerBuilder===>');
                if (mode == LoadStatus.idle) {
                  text = '上拉加载';
                } else if (mode == LoadStatus.loading) {
                  text = '加载中';
                } else if (mode == LoadStatus.failed) {
                  text = '加载失败，点击重新加载！';
                } else if (mode == LoadStatus.canLoading) {
                  text = '准备加载更多';
                } else if (mode == LoadStatus.noMore) {
                  text = '没有更多了';
                } else {
                  text = '';
                }
                return text.isEmpty
                    ? SizedBox.shrink()
                    : Container(
                        height: 55.0,
                        child: Center(
                            child: Text(
                          text,
                          style: TextStyle(
                              color: ColorUtil.rgba(255, 255, 255, 0.15)),
                        )),
                      );
              },
            ),
        enableLoadingWhenNoData: false,
        hideFooterWhenNotFull: false,
        shouldFooterFollowWhenNotFull: (state) {
          return true;
          // if (state == LoadStatus.noMore) {
          //   return true;
          // }
          // return false;
        },
        child: child);
  }
}
